package com.peaksport.framework.base.controller;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;

import org.apache.servicecomb.provider.springmvc.reference.async.CseAsyncRestTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.client.RestTemplate;

import com.peaksport.framework.exception.PKDevException;
import com.peaksport.framework.extend.redis.PKRedisTemplate;

public class BaseController {

	@Autowired
	public PKRedisTemplate pkRedisTemplate;
	
	@Autowired
	public RestTemplate restTemplate;
	
	@Autowired
	public CseAsyncRestTemplate asynRestTemplate;
	
	/**
	 * URL 反编码
	 * @param s
	 * @return
	 */
	public String urlDecode(String s) {
		try {
			return URLDecoder.decode(s,"UTF-8");
		} catch (UnsupportedEncodingException e) {
			throw PKDevException.throwException("URL解码异常:", e.getMessage());
		}
	}
	
	/**
	 * URL 编码
	 * @param s
	 * @return
	 */
	public String urlEncode(String s) {
		try {
			return URLEncoder.encode(s,"UTF-8");
		} catch (UnsupportedEncodingException e) {
			throw PKDevException.throwException("URL编码异常:", e.getMessage());
		}
	}
	
}
